package com.myweb.demo.repository;

import com.myweb.demo.entity.Plate;
import com.myweb.demo.entity.Posts;
import com.myweb.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface PostsRepository extends JpaRepository<Posts,Long> {

    @Override
    List<Posts> findAll();

    @Query("select p from Posts p where p.postsId = ?1 order by p.postsId desc ")
    Posts getPostsByPostsId(Long id);

    @Query("select p from Posts p where p.plate = ?1")
    List<Posts> getPostsByPlate(Plate plate);

    @Query("select p from Posts p ORDER BY p.postsDate desc ")
    List<Posts> getPostsOrderByDate();

    @Query("select p from Posts p where p.postsTitle like '%？'")
    List<Posts> getQuestionPosts();

    @Query("select p from Posts p where p.user = ?1")
    List<Posts> getPostsByUser(User user);
}
